"use strict";
/*cookie信息*/
module.exports= {
  //存储cookie信息
  setCookie:function (key,value,dayCount) {
      const d = new Date();
      // d.setDate(d.getDate()+dayCount);
      d.setTime(d.getTime()+dayCount*60*1000); //设置date为当前时间+30分
      document.cookie = key+"="+encodeURIComponent(value)+";expires="+d.toGMTString();
  },
  //获取cookie信息
  getCookie:function (key) {
      const str = decodeURIComponent(document.cookie);
      const arr = str.split("; ");
      for(var i=0;i<arr.length;i++){
        if(arr[i].indexOf(key+"=")==0){
          return arr[i].substring((key+"=").length);
        }
      }
      return "";
  },
  //保持删除用户信息
  removeCookie:function (key) {
    this.setCookie(key,"007",-5);
  },
  //退出登录
  logout:function(key){
    // this.setCookie(key, "", {expires: -1});
    console.log(key);
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = this.getCookie(key);
   if (cval != null){
     document.cookie = key + "=" + cval + ";expires=" + exp.toGMTString();
   }
   
  }
};
